/**
 * Created by win 10 on 2/6/2018.
 */
var num = 0;
var pageNum = num + 1
var totalPage;
$(function () {
    var isRank = $(".choice").val();
    var title = $(".notice-title").val();
    if (!$.cookie("FUND_USER_TOKEN")) {
        return false;
    }
    getNotice(isRank, title, num);
    $(".choice").change(function () {
        num = 0;
        isRank = $(".choice").val();
        title = $(".notice-title").val();
        $(".notice-list").empty();
        getNotice(isRank, title, num);
    })

    $("#search").click(function () {
        num = 0;
        isRank = $(".choice").val();
        title = $(".notice-title").val();
        $(".notice-list").empty();
        getNotice(isRank, title, num);
    })
})
function getNotice(isRank, title, num) {
    $.ajax({
        url: '/sichuansfc/fund/notify/search.bs?rank='+isRank+'&title='+title+'&size=10&num='+num,
        type: 'get',
        headers: {'FUND_USER_TOKEN': $.cookie('FUND_USER_TOKEN')},
        success: function (data) {
            if (data.status === 100000) {
                totalPage = Math.ceil(data.data.count / 10);
                for (var i = 0; i < data.data.pageList.length; i++) {
                    var readStatus = '';
                    var readClass = '';
                    if (data.data.pageList[i].isRead) {
                        readStatus = '已读';
                    } else {
                        readStatus = '未读';
                        readClass = 'waiting-read'
                    }
                    $(".notice-list").append(
                        '<li class="notice-list-item">'+
                        '<a class="read-detail" href="../html/noticeDetail.html?id='+data.data.pageList[i].id+'">'+ data.data.pageList[i].title +'</a>'+
                        '<span class="read-status '+readClass+'">'+readStatus+'</span>'+
                        '<span class="publish-time">'+new Date(data.data.pageList[i].addTime).Format('yyyy-MM-dd hh:mm:ss')+'</span>'+
                        '</li>'
                    )
                }
                /* 页码插件 */
                $("#page").paging({
                    pageNo: pageNum,
                    totalPage: totalPage ? totalPage : 1,
                    totalSize: 300,
                    callback: function(num) {
                        // window.console.log('page clicked : ' + num);
                        $(".notice-list").empty();
                        getNotice(isRank, title, num-1)
                        pageNum = num
                    }
                });
            }
        },
        error: function () {
            alert('服务器异常，请稍后重试')
        }
    })
}

